#!/bin/bash

# 快速API测试脚本
echo "====== TZAI 快速API测试 ======"
echo ""

# 使用当前的Token（需要先在前端登录获取）
# 或者使用以下命令重新登录获取Token
echo "1. 登录获取Token..."
LOGIN_RESULT=$(curl -s -X POST "http://localhost:8080/login" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "admin",
    "password": "admin123",
    "code": "123",
    "uuid": "test-uuid"
  }')

echo "登录结果: $LOGIN_RESULT"
echo ""

# 如果登录成功，提取Token
TOKEN=$(echo $LOGIN_RESULT | jq -r '.token // empty' 2>/dev/null)

if [ -z "$TOKEN" ]; then
  echo "❌ 登录失败，请检查验证码或使用已有Token"
  echo ""
  echo "您可以："
  echo "1. 在浏览器登录后台，按F12打开控制台"
  echo "2. 执行: localStorage.getItem('Admin-Token')"
  echo "3. 复制Token并修改此脚本中的TOKEN变量"
  exit 1
fi

echo "✅ Token获取成功"
echo ""

# 测试API
echo "2. 测试获取AI模型列表..."
curl -s -X GET "http://localhost:8080/tzai/ai/model/list" \
  -H "Authorization: Bearer $TOKEN" | jq '.rows[] | {modelId, modelName, provider, isDefault}'
echo ""

echo "3. 测试获取资讯列表..."
curl -s -X GET "http://localhost:8080/tzai/article/list" \
  -H "Authorization: Bearer $TOKEN" | jq '.rows[] | {articleId, title, status}'
echo ""

echo "====== 测试完成 ======"

